package com.jic.manager.impl;

import java.lang.Long;
import java.util.List;
import java.util.Random;

import com.jic.common.base.vo.RestResult;
import com.jic.manager.entity.MerchantWeBankBrand;
import com.jic.manager.mapper.MerchantWeBankBrandMapper;
import com.jic.manager.service.MerchantWeBankBrandService;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.Page;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 商户品牌信息表
 * @author : 
 * @email : 
 * @since : 2020-11-28 11:09:25
 * @version : v1.0.0
 */
@Service
public class MerchantWeBankBrandServiceImpl implements MerchantWeBankBrandService{

    @Resource
    private MerchantWeBankBrandMapper merchantWeBankBrandMapper;

    @Override
    public RestResult insert(MerchantWeBankBrand merchantWeBankBrand) {
        long flag = merchantWeBankBrandMapper.insert(merchantWeBankBrand);
        if (flag != 1){
            throw new RuntimeException("保存失败");
        }
        return RestResult.success(flag);
    }

    @Override
    public long delete(Long id) {
        return merchantWeBankBrandMapper.delete(id);
    }

    @Override
    public long update(MerchantWeBankBrand merchantWeBankBrand) {
        return merchantWeBankBrandMapper.update(merchantWeBankBrand);
    }

    @Override
    public MerchantWeBankBrand queryByPrimaryKey(Long id){
        return merchantWeBankBrandMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<MerchantWeBankBrand> query(MerchantWeBankBrand merchantWeBankBrand){
        return merchantWeBankBrandMapper.query(merchantWeBankBrand);
    }

    @Override
    public RestResult<PageResult<MerchantWeBankBrand>> queryPage(MerchantWeBankBrand merchantWeBankBrand) {
        //计算下标
        int startIndex = (merchantWeBankBrand.getStart() - 1) * merchantWeBankBrand.getLimit();
        List<MerchantWeBankBrand> list = merchantWeBankBrandMapper.queryPage(startIndex, merchantWeBankBrand.getLimit(), merchantWeBankBrand);
        long count = merchantWeBankBrandMapper.queryPageCount(merchantWeBankBrand);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return RestResult.success(pageResult);
    }
}